<!-- Copyright 2015 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -->
<!DOCTYPE html>
<title>Unit Test of e2e.otr.message.dhkey/</title>
<script src="../../../../../../javascript/closure/base.js"></script>
<script src="test_js_deps-runfiles.js"></script>
<script>
goog.require('e2e.otr.message.DhKey');
goog.require('goog.crypt');
goog.require('goog.testing.PropertyReplacer');
goog.require('goog.testing.asserts');
goog.require('goog.testing.jsunit');
</script>
<script>

var sender = new Uint8Array([0x00, 0x00, 0x01, 0x00]);
var receiver = new Uint8Array([0x00, 0x00, 0x02, 0x00]);

function testDhKey() {
  var stubs = new goog.testing.PropertyReplacer();

  // /lib/ake.js in handleAKE, case '\x02', type = '\x0a'
  // this.our_dh.publicKey
  // BigInt.bigInt2str(this.our_dh.privateKey, 16)
  var y = goog.crypt.hexToByteArray(
      'B1F9A3F247536F980550E544A41D6679A178EA16048AEFDC7734BD0B9B26EAA27A2FE5E8F97B236B');
  stubs.setPath('e2e.cipher.DiffieHellman.prototype.generateExponent_',
      function() {return y;});
  var dhkey = new e2e.otr.message.DhKey({
    instanceTag: sender,
    remoteInstanceTag: receiver
  });

  var out = dhkey.serializeMessageContent();
  assertEquals(196, out.length);

  // BigInt.bigInt2str(this.our_dh.publicKey, 16)
  assertArrayEquals(goog.crypt.hexToByteArray(
      'CF62D4A59A9FA6FF9B5202878FB99849A042C0A0405A878ADCA3080E0529F8B4E1918F5387E5B8926BFECD19507B15F9D9CFDEDD0EEE90BEA05B547FA13C66B6C0C763B745622CCF02BCFDF9020ABABDAD4A0B5DDC2883326CF32FAEEC7FCEB1EBF892CF5FCAFF3BA0583729BAD5E78DB309AEBABEB132A5AF0A00AF416D9E3731B241DE498E6387838854D44099648153D47E11C827C9532AF03AA3620610F619135517298D4ED6DBC22375A03B08274E04E6DC3B41AC07C34078929B872891'),
      dhkey.gy_);

  stubs.reset();
}
</script>

